/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.evolve.webbot.database;
import  java.sql.PreparedStatement;
import  java.sql.SQLException;
import  com.evolve.webbot.database.Conexion;
import  com.evolve.webbot.bean.LiverpoolMntBean;
/**
 *
 * @author DarthAE
 */
public class Insert 
{    
    public Insert(){}
    
    public int insertaLiverpoolMes(LiverpoolMntBean liverpool,
                                   Conexion con)
    {
        int rows = 0;  
        
        double ventaMesActual     = 0;
        double ventaMesAnterior   = 0;
        double ventaAcumuladaAnio = 0;
        int    invMesActual       = 0;
        int    onOrder            = 0;
        
        try{
             ventaMesActual     = Double.parseDouble(liverpool.getVentaMesActual());
             ventaMesAnterior   = Double.parseDouble(liverpool.getVentaMesAnterior());
             ventaAcumuladaAnio = Double.parseDouble(liverpool.getVentaAcumuladaAnio());
             invMesActual       = Integer.parseInt(liverpool.getInventarioMesActual());
             onOrder            = Integer.parseInt(liverpool.getOnOrder());
             
           }catch(Exception e){}
        
        String sql="";
        
        try{
             sql = "insert into liverpool_vm_articulo("+
                   "ewb_usr,ewb_pgm,ewb_fac,dte_dwd,  "+
                   "ctro_region,articulo,descripcion, "+  
                   "estado,modelo,ean_upc,temporada,  "+    
                   "vta_mes_act,vta_mes_ant,vta_acu_anio,"+ 
                   "inv_mes_act,on_order)   "+
                   "values ( 'admin',       "+
                       "'insertLiverM',"+
                       "now(),         "+
                       "curdate(),     "+
                       "'"+liverpool.getCentro()     +"',"+
                       "'"+liverpool.getArticulo()   +"',"+
                       "'"+liverpool.getDescripcion()+"',"+
                       "'"+liverpool.getEstado()     +"',"+
                       "'"+liverpool.getModelo()     +"',"+
                       "'"+liverpool.getEanUpc()     +"',"+
                       "'"+liverpool.getTemporada()  +"',"+
                       ventaMesActual    +","+
                       ventaMesAnterior  +","+
                       ventaAcumuladaAnio+","+
                       invMesActual      +","+
                       onOrder+                       
                      ")";
        
            System.out.println(sql);        
        
            PreparedStatement stmt = con.getConnection().prepareStatement(sql);
            rows = stmt.executeUpdate();
            stmt.close();
            
        }catch(SQLException sqlex){System.out.println(sqlex);} 
         catch(Exception e){System.out.println(e);}
        
        return rows;
    }
}
